home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / xbm_edit.pro < prev    next >
Text File  |  1997-07-08  |  28KB  |  938 lines

  1. ; $Id: xbm_edit.pro,v 1.7 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;    XBM_EDIT
  8. ;
  9. ; PURPOSE:
  10. ;    This routine allows users to create and edit bitmaps for use with IDL
  11. ;    widgets as icons.
  12. ;
  13. ;    The icons can be saved in two different file formats.  IDL "array 
  14. ;    definition files" are text files that can be inserted into IDL 
  15. ;    programs.  "Bitmap array files" are data files that can be read into 
  16. ;    IDL programs.  Bitmap array files are to be used temporarily until 
  17. ;    the final icon design is determined and then they can be saved as 
  18. ;    IDL array definitions for inclusion in the final code.  This routine 
  19. ;    does not check the file types of the files being read in and assumes 
  20. ;    that they are of the correct size and type for reading.
  21. ;
  22. ; CATEGORY:
  23. ;    Widgets.
  24. ;
  25. ; CALLING SEQUENCE:
  26. ;    XBM_EDIT
  27. ;
  28. ; KEYWORD PARAMETERS:
  29. ;     FILENAME:    A scalar string that contains the file name to be used.  If 
  30. ;        this argument is not specified, the name "idl.bm" is used.
  31. ;
  32. ;    GROUP:    The widget ID of the widget that calls XBM_EDIT.  When this
  33. ;        ID is specified, the death of the caller results in the death
  34. ;        of XBM_EDIT.
  35. ;
  36. ;    XSIZE:    The number of pixels across the bitmap is in the horizontal
  37. ;        direction.  The default value is 16 pixels.
  38. ;
  39. ;    YSIZE:    The number of pixels across the bitmap is in the vertical
  40. ;        direction.  The default value is 16 pixels.
  41. ;
  42. ; SIDE EFFECTS:
  43. ;    Initiates the XManager if it is not already running.
  44. ;
  45. ;    Note that rotating an XSIZE x YSIZE bitmap by 90 net degrees
  46. ;    changes it to a YSIZE x XSIZE bitmap.
  47. ;
  48. ; RESTRICTIONS:
  49. ;    XBM_EDIT maintains its state in a common block so it is restricted
  50. ;    to one working copy at a time.
  51. ;
  52. ; PROCEDURE:
  53. ;    Create and register the widget and then exit.
  54. ;
  55. ; MODIFICATION HISTORY:
  56. ;    Created from a template written by: Steve Richards, January, 1991
  57. ;    1/96, RPM - fixed bugs so non-square bitmaps can be rotated;
  58. ;            fixed bug so doesn't hang if draw a single pixel "line";
  59. ;            fixed bugs so can read bitmap array files that are not
  60. ;            square and don't end on byte boundaries;
  61. ;            added FREE_LUN and made several other minor fixes.
  62. ;-
  63.  
  64.  
  65.  
  66. ;------------------------------------------------------------------------------
  67. ;    procedure update_display
  68. ;------------------------------------------------------------------------------
  69. ; This procedure redraws both the drawing area and the small icon example 
  70. ; displays.
  71. ;------------------------------------------------------------------------------
  72.  
  73. PRO update_display, ROTATE=ROTATE
  74.  
  75. COMMON bitedit, bytemap, drawwin, showwin, thexsize, theysize, multiplier, $
  76.         nameid, drawmode
  77. COMMON rotatestuff, xbm_draw, xbm_show, xsize_draw, ysize_draw, not_square
  78.  
  79. swin = !d.window
  80. wset, showwin
  81. IF(KEYWORD_SET(ROTATE) AND not_square)THEN BEGIN
  82.   ERASE
  83.   temp = thexsize  &  thexsize = theysize  &  theysize = temp
  84.   WIDGET_CONTROL, xbm_show, $
  85.           DRAW_XSIZE=thexsize * 2 + 18, DRAW_YSIZE=theysize + 12
  86. ENDIF
  87. tv, 255 - bytemap, 6, 6
  88. tv, bytemap, thexsize + 12 , 6
  89.  
  90. wset, drawwin
  91. IF(KEYWORD_SET(ROTATE) AND not_square)THEN BEGIN
  92.   ERASE
  93.   temp = xsize_draw  &  xsize_draw = ysize_draw  &  ysize_draw = temp
  94.   WIDGET_CONTROL, xbm_draw, DRAW_XSIZE=xsize_draw, DRAW_YSIZE=ysize_draw
  95. ENDIF
  96. grid = 255 - REBIN(bytemap, $
  97.         thexsize * multiplier, $
  98.         theysize * multiplier, /SAMPLE)
  99. FOR i = 0, thexsize - 1 do grid[i * multiplier, *] = 150
  100. FOR i = 0, theysize - 1 do grid[*, i * multiplier] = 150
  101. tv, grid
  102. wset, swin
  103.  
  104. END ;============= end of xbm_edit display update routine  =============
  105.  
  106.  
  107. ;------------------------------------------------------------------------------
  108. ;    procedure draw_pixel
  109. ;------------------------------------------------------------------------------
  110. ; This routine draws a pixel on the drawing area of the widget.  When the MARK
  111. ; keyword is set, a pixel with a mark is drawn to be used when drawing lines,
  112. ; circles, and rectangles.
  113. ;------------------------------------------------------------------------------
  114.  
  115. PRO draw_pixel, x, y, color, MARK = MARK
  116.  
  117. COMMON bitedit, bytemap, drawwin, showwin, thexsize, theysize, multiplier, $
  118.         nameid, drawmode
  119.  
  120. swin = !d.window
  121. IF(KEYWORD_SET(MARK))THEN BEGIN
  122.   little = BYTARR(multiplier-1, multiplier-1)
  123.   FOR i = 0, multiplier-2 DO BEGIN
  124.     little[i,i] = 255
  125.     little[i,multiplier-i-2] = 255
  126.   END
  127.   WSET, drawwin
  128.   tv, little, multiplier * x + 1, multiplier * y + 1
  129. ENDIF ELSE BEGIN
  130.   little = bytarr(multiplier-1, multiplier-1) + color
  131.   wset, drawwin
  132.   tv, little, multiplier * x + 1, multiplier * y + 1
  133.   wset, showwin
  134.   tv, 255 - bytemap, 6, 6
  135.   tv, bytemap, thexsize + 12, 6
  136. ENDELSE
  137. WSET, swin
  138.  
  139. END ;============= end of xbm_edit pixel draw routine  =============
  140.  
  141.  
  142. ;------------------------------------------------------------------------------
  143. ;    procedure xbm_edit_ev
  144. ;------------------------------------------------------------------------------
  145. ; This procedure processes the events being sent from the xmanager.
  146. ;------------------------------------------------------------------------------
  147.  
  148. PRO xbm_edit_ev, event
  149.  
  150. COMMON bitedit, bytemap, drawwin, showwin, thexsize, theysize, multiplier, $
  151.         nameid, drawmode
  152. COMMON eventstuff, lastx, lasty
  153.  
  154. WIDGET_CONTROL, event.id, GET_UVALUE = eventval        ;find the user value
  155.                             ;of the widget where
  156.                             ;the event occured
  157. CASE eventval OF
  158.  
  159.   "XLOADCT": XLoadct, GROUP = event.top
  160.  
  161.   "XPALETTE": XPalette, GROUP = event.top
  162.  
  163.   "XMANTOOL": XMTool, GROUP = event.top
  164.  
  165.   "DRAW": BEGIN
  166.     event.x = 0 > event.x < (thexsize * multiplier - 1)
  167.     event.y = 0 > event.y < (theysize * multiplier - 1)
  168.     xpos = (event.x / multiplier)
  169.     ypos = (event.y / multiplier)
  170.     IF((event.press NE 0)) THEN BEGIN
  171.       CASE drawmode OF
  172.  
  173.         0: IF(bytemap[xpos, ypos] NE 0) THEN BEGIN
  174.          bytemap[xpos, ypos] = 0
  175.          draw_pixel, xpos, ypos, 255
  176.          drawmode = 2
  177.            ENDIF ELSE BEGIN
  178.          bytemap[xpos, ypos] = 255
  179.          draw_pixel, xpos, ypos, 0
  180.          drawmode = 1
  181.            ENDELSE
  182.  
  183.         3: BEGIN
  184.          draw_pixel, xpos, ypos, 0, /MARK
  185.          lastx = xpos
  186.          lasty = ypos
  187.            END
  188.  
  189.         4: BEGIN
  190.          draw_pixel, xpos, ypos, 0, /MARK
  191.          lastx = xpos
  192.          lasty = ypos
  193.            END
  194.  
  195.         5: BEGIN
  196.          draw_pixel, xpos, ypos, 0, /MARK
  197.          lastx = xpos
  198.          lasty = ypos
  199.            END
  200.         ELSE:
  201.       ENDCASE
  202.     ENDIF ELSE IF((event.press EQ 0) AND (event.release EQ 0)) THEN BEGIN
  203.       CASE drawmode OF
  204.  
  205.         0: BEGIN
  206.          lastx = -1
  207.          lasty = -1
  208.            END
  209.  
  210.         1: IF(NOT((xpos EQ lastx) AND (ypos EQ lasty))) THEN BEGIN
  211.          lastx = xpos
  212.          lasty = ypos
  213.          bytemap[xpos, ypos] = 255
  214.          draw_pixel, xpos, ypos, 0
  215.            ENDIF
  216.  
  217.         2: IF(NOT((xpos EQ lastx) AND (ypos EQ lasty))) THEN BEGIN
  218.          lastx = xpos
  219.          lasty = ypos
  220.          bytemap[xpos, ypos] = 0
  221.          draw_pixel, xpos, ypos, 255
  222.         ENDIF
  223.  
  224.         ELSE:
  225.       ENDCASE
  226.     ENDIF ELSE IF(event.release EQ 1) THEN BEGIN
  227.       CASE drawmode OF
  228.  
  229.         1: drawmode = 0
  230.  
  231.         2: drawmode = 0
  232.  
  233.         3: BEGIN                    ;Circle
  234.          smallx = lastx < xpos
  235.          bigx = lastx > xpos
  236.          smally = lasty < ypos
  237.          bigy = lasty > ypos
  238.          xrad = (bigx - smallx)/2.
  239.          yrad = (bigy - smally)/2.
  240.          cy = smally + yrad
  241.          cx = smallx + xrad
  242.          samples = xrad * yrad * 4.0
  243.                  IF samples NE 0 THEN BEGIN
  244.                     FOR i = 0, samples DO BEGIN
  245.                         a = (i/samples)*!pi*2
  246.                         bytemap[cx + cos(a)*xrad, cy + sin(a)*yrad] = 255
  247.                     ENDFOR
  248.                  ENDIF ELSE BEGIN
  249.                     a=0
  250.                     bytemap[cx + cos(a)*xrad, cy + sin(a)*yrad] = 255
  251.                  ENDELSE
  252.          update_display
  253.          drawmode = 0
  254.            END
  255.  
  256.         4: BEGIN                    ;Rectangle
  257.          smallx = lastx < xpos
  258.          bigx = lastx > xpos
  259.          smally = lasty < ypos
  260.          bigy = lasty > ypos
  261.          FOR i = smallx, bigx DO BEGIN
  262.            bytemap[i,smally] = 255
  263.            bytemap[i,bigy] = 255
  264.          ENDFOR
  265.          FOR i = smally, bigy DO BEGIN
  266.            bytemap[smallx, i] = 255
  267.            bytemap[bigx, i] = 255
  268.          ENDFOR
  269.          update_display
  270.          drawmode = 0
  271.            END
  272.  
  273.         5: BEGIN                    ;Generalized Bresenhams
  274.          x = lastx                ;Line Drawing Algorithm
  275.          y = lasty
  276.          deltax = ABS(xpos - lastx)
  277.          deltay = ABS(ypos - lasty)
  278.          IF (deltax EQ 0) AND (deltay EQ 0) THEN $
  279.            bytemap[x,y] = 255 $
  280.          ELSE BEGIN
  281.            so = -1 > (xpos - lastx) < 1
  282.            st = -1 > (ypos - lasty) < 1
  283.            IF(deltay GT deltax) THEN BEGIN
  284.              temp = deltax
  285.              deltax = deltay
  286.              deltay = temp
  287.              interchange = 1
  288.            ENDIF ELSE interchange = 0
  289.            ebar = 2 * deltay - deltax
  290.            FOR i = 1, deltax + 1 DO BEGIN
  291.              bytemap[x,y] = 255
  292.              WHILE(ebar GE 0) DO BEGIN
  293.                IF(interchange EQ 1) THEN x = x + so ELSE y = y + st
  294.                ebar = ebar - 2 * deltax
  295.              ENDWHILE
  296.              IF(interchange EQ 1) THEN y = y + st ELSE x = x + so
  297.              ebar = ebar + 2 * deltay
  298.            ENDFOR
  299.          ENDELSE
  300.          update_display
  301.          drawmode = 0
  302.            END
  303.          
  304.       ELSE:
  305.       ENDCASE
  306.     ENDIF
  307.       END
  308.  
  309.   "SVBM": BEGIN
  310.         WIDGET_CONTROL, nameid, GET_VALUE = filename
  311.         xdim = thexsize / 8
  312.         IF((thexsize MOD 8) NE 0) THEN xdim = xdim + 1
  313.          data = BYTARR(xdim, theysize)
  314.         FOR y = 0, theysize - 1 DO $
  315.           FOR x = 0, thexsize - 1 DO BEGIN
  316.         IF((bytemap[x,y] AND 2^(x mod 8)) NE 0) THEN $
  317.               data[x / 8, theysize-y-1] = data[x/8,theysize-y-1] OR $
  318.                         2^(x mod 8)
  319.           ENDFOR
  320.         OPENW, unit, filename[0], /GET_LUN
  321.         WRITEU, unit, data
  322.         FREE_LUN, unit
  323.       END
  324.  
  325.   "RDBM": BEGIN
  326.         WIDGET_CONTROL, nameid, GET_VALUE = filename
  327.         OPENR, unit, filename[0], /GET_LUN
  328.         fsize = FSTAT(unit)
  329.         xdim = thexsize / 8
  330.         IF((thexsize MOD 8) NE 0) THEN xdim = xdim + 1
  331.         IF fsize.size NE (xdim * LONG(theysize)) THEN BEGIN
  332.         FREE_LUN, unit
  333.         MESSAGE, 'File bytes should be: '+string(xdim * LONG(theysize))
  334.         ENDIF
  335.          data = BYTARR(xdim, theysize)
  336.         READU, unit, data
  337.         FREE_LUN, unit
  338.         bytemap = BYTARR(thexsize, theysize)
  339.         FOR y = 0, theysize - 1 DO BEGIN
  340.           FOR x = 0, thexsize - 1 DO BEGIN
  341.         IF((data[x/8, y] AND (2^(x mod 8))) NE 0) THEN $
  342.           bytemap[(x/8)*8 + (x mod 8), theysize-y-1] = 255
  343.           ENDFOR
  344.         ENDFOR
  345.         update_display
  346.       END
  347.  
  348.   "SVIA": BEGIN
  349.         WIDGET_CONTROL, nameid, GET_VALUE = filename
  350.         xdim = thexsize / 8
  351.         IF((thexsize MOD 8) NE 0) THEN xdim = xdim + 1
  352.          data = BYTARR(xdim, theysize)
  353.         FOR y = 0, theysize - 1 DO $
  354.           FOR x = 0, thexsize - 1 DO BEGIN
  355.         IF((bytemap[x,y] AND 2^(x mod 8)) NE 0) THEN $
  356.               data[x/8, theysize-y-1] = data[x/8,theysize-y-1] OR $
  357.                         2^(x mod 8)
  358.           ENDFOR
  359.         IF !VERSION.OS NE "MacOS" THEN newline = string(10B) $
  360.         ELSE newline = string(13B)
  361.         OPENW, unit, filename[0], /GET_LUN
  362.         WRITEU, unit, + $
  363.         "                            ;" + $
  364.         filename[0] + " bitmap" + newline + $
  365.         "                            ;" + $
  366.         "definition" + newline
  367.         WRITEU, unit, filename[0] + $
  368.         " =     [                $"
  369.         WRITEU, unit, newline
  370.         FOR y = 0, theysize - 1 DO BEGIN
  371.           line = string(data[*,y], $
  372.         format = '("        [",(i3.3,"B",:,", "))')
  373.           WRITEU, unit, line
  374.           WRITEU, unit, "]"
  375.           IF(y LT theysize-1) THEN $
  376.         WRITEU, unit ,",            $" + newline $
  377.           ELSE WRITEU, unit, "            $" + newline
  378.         ENDFOR
  379.         WRITEU, unit, "        ]"
  380.         FREE_LUN, unit
  381.       END
  382.  
  383.   "erase.bm": BEGIN
  384.         bytemap = bytarr(thexsize, theysize)
  385.         update_display
  386.         WIDGET_CONTROL, event.id, SET_BUTTON = 0
  387.           END
  388.  
  389.   "cw.bm": BEGIN
  390.         bytemap = rotate(bytemap, 3)
  391.         update_display, /ROTATE
  392.         WIDGET_CONTROL, event.id, SET_BUTTON = 0
  393.        END
  394.  
  395.   "ccw.bm": BEGIN
  396.         bytemap = rotate(bytemap, 1)
  397.         update_display, /ROTATE
  398.         WIDGET_CONTROL, event.id, SET_BUTTON = 0
  399.         END
  400.  
  401.   "flip.bm":BEGIN
  402.         bytemap = rotate(bytemap, 5)
  403.         update_display
  404.         WIDGET_CONTROL, event.id, SET_BUTTON = 0
  405.         END
  406.  
  407.   "invert.bm": BEGIN
  408.          bytemap = 255 - bytemap
  409.          update_display
  410.         WIDGET_CONTROL, event.id, SET_BUTTON = 0
  411.            END
  412.  
  413.   "circle.bm": BEGIN
  414.         drawmode = 3
  415.         WIDGET_CONTROL, event.id, SET_BUTTON = 0
  416.            END
  417.  
  418.   "rect.bm": BEGIN
  419.         drawmode = 4
  420.         WIDGET_CONTROL, event.id, SET_BUTTON = 0
  421.          END
  422.  
  423.   "line.bm": BEGIN
  424.         drawmode = 5
  425.         WIDGET_CONTROL, event.id, SET_BUTTON = 0
  426.          END
  427.  
  428.   "FILENAME": 
  429.  
  430.   "EXIT": WIDGET_CONTROL, event.top, /DESTROY
  431.  
  432.   ELSE: MESSAGE, "Event User Value Not Found"
  433.  
  434. ENDCASE
  435.  
  436. END ;============= end of xbm_edit event handling routine task =============
  437.  
  438.  
  439. ;------------------------------------------------------------------------------
  440. ;    procedure xbm_edit
  441. ;------------------------------------------------------------------------------
  442. ; This is the main routine, it creates and then registers the widget with the
  443. ; XManager.
  444. ;------------------------------------------------------------------------------
  445.  
  446. PRO xbm_edit, XSIZE = XSIZE, YSIZE = YSIZE, GROUP = GROUP, FILENAME = FILENAME
  447.  
  448. COMMON bitedit, bytemap, drawwin, showwin, thexsize, theysize, multiplier, $
  449.         nameid, drawmode
  450.  
  451. COMMON rotatestuff, xbm_draw, xbm_show, xsize_draw, ysize_draw, not_square
  452.  
  453. COMMON eventstuff, lastx, lasty
  454.  
  455. IF(XRegistered("xbm_edit")) THEN RETURN            ;only one instance of
  456.                             ;the xbm_edit widget
  457.                             ;is allowed.  If it is
  458.                             ;already managed, do
  459.                             ;nothing and return
  460.  
  461. IF(NOT(KEYWORD_SET(FILENAME)))THEN FILENAME = "idl.bm"
  462. IF(NOT(KEYWORD_SET(XSIZE)))THEN XSIZE = 16
  463. IF(NOT(KEYWORD_SET(YSIZE)))THEN YSIZE = 16
  464.  
  465. IF(XSIZE LT 17) THEN mult = 14 ELSE mult = 8
  466.  
  467. bytemap = bytarr(XSIZE,YSIZE)
  468. drawwin = 0
  469. showwin = 0
  470. thexsize = ROUND(XSIZE)
  471. theysize = ROUND(YSIZE)
  472. not_square = thexsize NE theysize
  473.  
  474. multiplier = mult
  475. nameid = 0L
  476. drawmode = 0L
  477.  
  478. xbm_editbase = WIDGET_BASE(TITLE = "xbm_edit", $
  479.         /COLUMN)                ;create the main base
  480. ; Setting the managed attribute indicates our intention to put this app
  481. ; under the control of XMANAGER, and prevents our draw widgets from
  482. ; becoming candidates for becoming the default window on WSET, -1. XMANAGER
  483. ; sets this, but doing it here prevents our own WSETs at startup from
  484. ; having that problem.
  485. WIDGET_CONTROL, /MANAGED, xbm_editbase
  486. swin = !d.window
  487.  
  488. XPdMenu, [    '"Done"                    EXIT',        $
  489.         '"File"    {',                        $
  490.         '"Save BitMap Array File"        SVBM',        $
  491.         '"Save IDL Array Definition File"     SVIA',        $
  492.         '"Read BitMap Array File"        RDBM',        $
  493.         '}',                            $
  494.         '"Tools"    {',                    $
  495.             '"XLoadct"            XLOADCT',    $
  496.             '"XPalette"            XPALETTE',    $
  497.             '"XManagerTool"            XMANTOOL',    $
  498.         '}'],                            $
  499.     xbm_editbase
  500.  
  501. xbm_topbase = WIDGET_BASE(xbm_editbase, $
  502.         /ROW)
  503.  
  504. version = WIDGET_INFO(/version)
  505. IF VERSION.STYLE EQ 'OPEN LOOK' THEN $
  506.   xbm_palette = WIDGET_BASE(xbm_topbase, $
  507.         COLUMN = 2, $
  508.         /FRAME, $
  509.         /EXCLUSIVE) $
  510. ELSE $
  511.   xbm_palette = WIDGET_BASE(xbm_topbase, $
  512.         COLUMN = 2, $
  513.         /FRAME)
  514.  
  515. controls = [    "erase.bm",        $
  516.         "line.bm",        $
  517.         "rect.bm",        $
  518.         "circle.bm",        $
  519.         "cw.bm",        $
  520.         "ccw.bm",        $
  521.         "flip.bm",        $
  522.         "invert.bm"        $
  523.     ]
  524.  
  525. controlicons = [                        $
  526.         ;eraser icon
  527.          [                        $
  528.         [000B, 000B, 000B, 000B, 000B],            $
  529.         [000B, 000B, 000B, 000B, 000B],            $
  530.         [000B, 000B, 000B, 000B, 000B],            $
  531.         [000B, 000B, 000B, 000B, 000B],            $
  532.         [000B, 000B, 000B, 000B, 000B],            $
  533.         [000B, 000B, 000B, 000B, 000B],            $
  534.         [000B, 000B, 000B, 000B, 000B],            $
  535.         [000B, 000B, 000B, 000B, 000B],            $
  536.         [000B, 000B, 000B, 000B, 000B],            $
  537.         [000B, 000B, 000B, 000B, 000B],            $
  538.         [000B, 000B, 000B, 000B, 000B],            $
  539.         [000B, 000B, 000B, 000B, 000B],            $
  540.         [000B, 000B, 000B, 000B, 000B],            $
  541.         [000B, 000B, 000B, 000B, 000B],            $
  542.         [000B, 252B, 255B, 255B, 031B],            $
  543.         [000B, 003B, 000B, 000B, 022B],            $
  544.         [192B, 000B, 000B, 128B, 017B],            $
  545.         [224B, 255B, 255B, 127B, 008B],            $
  546.         [032B, 000B, 000B, 064B, 008B],            $
  547.         [032B, 000B, 000B, 064B, 008B],            $
  548.         [016B, 000B, 000B, 032B, 004B],            $
  549.         [016B, 000B, 000B, 032B, 004B],            $
  550.         [016B, 000B, 000B, 032B, 004B],            $
  551.         [008B, 000B, 000B, 016B, 002B],            $
  552.         [008B, 000B, 000B, 016B, 002B],            $
  553.         [008B, 000B, 000B, 016B, 003B],            $
  554.         [004B, 000B, 000B, 200B, 000B],            $
  555.         [004B, 000B, 000B, 056B, 000B],            $
  556.         [252B, 255B, 255B, 015B, 000B],            $
  557.         [000B, 000B, 000B, 000B, 000B],            $
  558.         [000B, 000B, 000B, 000B, 000B],            $
  559.         [000B, 000B, 000B, 000B, 000B],            $
  560.         [000B, 000B, 000B, 000B, 000B],            $
  561.         [000B, 000B, 000B, 000B, 000B],            $
  562.         [000B, 000B, 000B, 000B, 000B],            $
  563.         [000B, 000B, 000B, 000B, 000B],            $
  564.         [000B, 000B, 000B, 000B, 000B],            $
  565.         [000B, 000B, 000B, 000B, 000B],            $
  566.         [000B, 000B, 000B, 000B, 000B],            $
  567.         [000B, 000B, 000B, 000B, 000B]            $
  568.         ],                        $
  569.         ;line icon
  570.         [                        $
  571.         [000B, 000B, 000B, 000B, 000B],            $
  572.         [000B, 000B, 000B, 000B, 000B],            $
  573.         [000B, 000B, 000B, 000B, 000B],            $
  574.         [000B, 000B, 000B, 000B, 000B],            $
  575.         [000B, 004B, 000B, 000B, 000B],            $
  576.         [000B, 004B, 000B, 000B, 000B],            $
  577.         [000B, 004B, 000B, 000B, 000B],            $
  578.         [000B, 004B, 000B, 000B, 000B],            $
  579.         [000B, 002B, 000B, 000B, 000B],            $
  580.         [000B, 002B, 000B, 000B, 000B],            $
  581.         [000B, 002B, 000B, 000B, 000B],            $
  582.         [000B, 002B, 000B, 000B, 000B],            $
  583.         [000B, 001B, 000B, 000B, 000B],            $
  584.         [000B, 001B, 000B, 000B, 000B],            $
  585.         [000B, 001B, 000B, 192B, 015B],            $
  586.         [000B, 001B, 224B, 063B, 000B],            $
  587.         [128B, 240B, 031B, 000B, 000B],            $
  588.         [128B, 000B, 000B, 000B, 000B],            $
  589.         [128B, 000B, 000B, 000B, 000B],            $
  590.         [128B, 000B, 000B, 000B, 000B],            $
  591.         [064B, 000B, 000B, 000B, 000B],            $
  592.         [064B, 000B, 000B, 000B, 000B],            $
  593.         [064B, 064B, 000B, 000B, 000B],            $
  594.         [064B, 128B, 000B, 000B, 000B],            $
  595.         [032B, 000B, 001B, 000B, 000B],            $
  596.         [032B, 000B, 002B, 000B, 000B],            $
  597.         [032B, 000B, 004B, 000B, 000B],            $
  598.         [032B, 000B, 008B, 000B, 000B],            $
  599.         [016B, 000B, 016B, 000B, 000B],            $
  600.         [016B, 000B, 032B, 000B, 000B],            $
  601.         [016B, 000B, 064B, 000B, 000B],            $
  602.         [016B, 000B, 128B, 000B, 000B],            $
  603.         [008B, 000B, 000B, 001B, 000B],            $
  604.         [008B, 000B, 000B, 002B, 000B],            $
  605.         [008B, 000B, 000B, 004B, 000B],            $
  606.         [008B, 000B, 000B, 008B, 000B],            $
  607.         [000B, 000B, 000B, 016B, 000B],            $
  608.         [000B, 000B, 000B, 000B, 000B],            $
  609.         [000B, 000B, 000B, 000B, 000B],            $
  610.         [000B, 000B, 000B, 000B, 000B]            $
  611.         ],                        $
  612.         ;rect icon
  613.          [                        $
  614.         [000B, 000B, 000B, 000B, 000B],            $
  615.         [000B, 000B, 000B, 000B, 000B],            $
  616.         [000B, 000B, 000B, 000B, 000B],            $
  617.         [000B, 000B, 000B, 000B, 000B],            $
  618.         [000B, 000B, 000B, 000B, 000B],            $
  619.         [224B, 255B, 255B, 031B, 000B],            $
  620.         [032B, 000B, 000B, 016B, 000B],            $
  621.         [032B, 000B, 000B, 016B, 000B],            $
  622.         [032B, 000B, 000B, 016B, 000B],            $
  623.         [032B, 000B, 000B, 016B, 000B],            $
  624.         [032B, 000B, 000B, 016B, 000B],            $
  625.         [032B, 000B, 000B, 016B, 000B],            $
  626.         [032B, 000B, 000B, 016B, 000B],            $
  627.         [032B, 000B, 000B, 016B, 000B],            $
  628.         [032B, 000B, 000B, 016B, 000B],            $
  629.         [032B, 000B, 000B, 016B, 000B],            $
  630.         [032B, 000B, 000B, 016B, 000B],            $
  631.         [032B, 000B, 000B, 016B, 000B],            $
  632.         [032B, 000B, 000B, 016B, 000B],            $
  633.         [224B, 255B, 255B, 031B, 000B],            $
  634.         [000B, 000B, 000B, 000B, 000B],            $
  635.         [000B, 000B, 000B, 000B, 000B],            $
  636.         [000B, 000B, 000B, 000B, 000B],            $
  637.         [000B, 063B, 000B, 000B, 000B],            $
  638.         [000B, 033B, 000B, 000B, 000B],            $
  639.         [000B, 033B, 000B, 000B, 000B],            $
  640.         [000B, 033B, 000B, 000B, 000B],            $
  641.         [000B, 033B, 000B, 252B, 015B],            $
  642.         [000B, 033B, 000B, 004B, 008B],            $
  643.         [000B, 033B, 000B, 004B, 008B],            $
  644.         [000B, 033B, 000B, 004B, 008B],            $
  645.         [000B, 033B, 000B, 004B, 008B],            $
  646.         [000B, 033B, 000B, 004B, 008B],            $
  647.         [000B, 033B, 000B, 004B, 008B],            $
  648.         [000B, 033B, 000B, 004B, 008B],            $
  649.         [000B, 033B, 000B, 252B, 015B],            $
  650.         [000B, 063B, 000B, 000B, 000B],            $
  651.         [000B, 000B, 000B, 000B, 000B],            $
  652.         [000B, 000B, 000B, 000B, 000B],            $
  653.         [000B, 000B, 000B, 000B, 000B]            $
  654.         ],                        $
  655.         ;circle icon
  656.          [                        $
  657.         [000B, 000B, 000B, 000B, 000B],            $
  658.         [000B, 000B, 000B, 000B, 000B],            $
  659.         [000B, 192B, 031B, 000B, 000B],            $
  660.         [000B, 056B, 224B, 000B, 000B],            $
  661.         [000B, 006B, 000B, 003B, 000B],            $
  662.         [000B, 001B, 000B, 004B, 000B],            $
  663.         [128B, 000B, 000B, 008B, 000B],            $
  664.         [064B, 000B, 000B, 016B, 000B],            $
  665.         [032B, 000B, 000B, 032B, 000B],            $
  666.         [032B, 000B, 000B, 032B, 000B],            $
  667.         [016B, 000B, 000B, 064B, 000B],            $
  668.         [016B, 000B, 000B, 064B, 000B],            $
  669.         [016B, 000B, 000B, 064B, 000B],            $
  670.         [008B, 000B, 000B, 128B, 000B],            $
  671.         [008B, 000B, 000B, 128B, 000B],            $
  672.         [008B, 000B, 000B, 128B, 000B],            $
  673.         [008B, 000B, 000B, 128B, 000B],            $
  674.         [008B, 000B, 000B, 128B, 000B],            $
  675.         [008B, 000B, 000B, 128B, 000B],            $
  676.         [008B, 000B, 000B, 128B, 000B],            $
  677.         [016B, 000B, 000B, 064B, 000B],            $
  678.         [016B, 000B, 000B, 064B, 000B],            $
  679.         [016B, 000B, 000B, 064B, 000B],            $
  680.         [032B, 000B, 000B, 032B, 000B],            $
  681.         [032B, 000B, 000B, 032B, 000B],            $
  682.         [064B, 000B, 000B, 016B, 000B],            $
  683.         [128B, 000B, 000B, 008B, 000B],            $
  684.         [000B, 001B, 000B, 004B, 000B],            $
  685.         [000B, 006B, 000B, 227B, 000B],            $
  686.         [000B, 056B, 224B, 016B, 001B],            $
  687.         [000B, 192B, 031B, 008B, 002B],            $
  688.         [000B, 000B, 000B, 008B, 002B],            $
  689.         [000B, 000B, 000B, 008B, 002B],            $
  690.         [000B, 000B, 000B, 016B, 001B],            $
  691.         [000B, 000B, 000B, 224B, 000B],            $
  692.         [000B, 000B, 000B, 000B, 000B],            $
  693.         [000B, 000B, 000B, 000B, 000B],            $
  694.         [000B, 000B, 000B, 000B, 000B],            $
  695.         [000B, 000B, 000B, 000B, 000B],            $
  696.         [000B, 000B, 000B, 000B, 000B]            $
  697.         ],                        $
  698.         ;clockwise rotation icon
  699.          [                        $
  700.         [000B, 000B, 000B, 000B, 000B],            $
  701.         [000B, 000B, 000B, 000B, 000B],            $
  702.         [000B, 000B, 000B, 000B, 000B],            $
  703.         [000B, 000B, 000B, 000B, 000B],            $
  704.         [000B, 000B, 000B, 000B, 000B],            $
  705.         [000B, 000B, 000B, 000B, 000B],            $
  706.         [192B, 127B, 000B, 000B, 000B],            $
  707.         [064B, 128B, 007B, 000B, 000B],            $
  708.         [064B, 000B, 024B, 000B, 000B],            $
  709.         [064B, 000B, 096B, 000B, 000B],            $
  710.         [064B, 000B, 128B, 001B, 000B],            $
  711.         [064B, 000B, 000B, 002B, 000B],            $
  712.         [064B, 000B, 000B, 004B, 000B],            $
  713.         [064B, 000B, 000B, 008B, 000B],            $
  714.         [064B, 000B, 000B, 016B, 000B],            $
  715.         [192B, 063B, 000B, 016B, 000B],            $
  716.         [000B, 192B, 001B, 032B, 000B],            $
  717.         [000B, 000B, 002B, 032B, 000B],            $
  718.         [000B, 000B, 004B, 064B, 000B],            $
  719.         [000B, 000B, 008B, 064B, 000B],            $
  720.         [000B, 000B, 016B, 064B, 000B],            $
  721.         [000B, 000B, 016B, 064B, 000B],            $
  722.         [000B, 000B, 016B, 128B, 000B],            $
  723.         [000B, 000B, 032B, 128B, 000B],            $
  724.         [000B, 000B, 032B, 128B, 000B],            $
  725.         [000B, 000B, 032B, 128B, 000B],            $
  726.         [000B, 000B, 063B, 128B, 031B],            $
  727.         [000B, 000B, 002B, 000B, 008B],            $
  728.         [000B, 000B, 004B, 000B, 004B],            $
  729.         [000B, 000B, 008B, 000B, 002B],            $
  730.         [000B, 000B, 016B, 000B, 001B],            $
  731.         [000B, 000B, 032B, 128B, 000B],            $
  732.         [000B, 000B, 064B, 064B, 000B],            $
  733.         [000B, 000B, 128B, 032B, 000B],            $
  734.         [000B, 000B, 000B, 017B, 000B],            $
  735.         [000B, 000B, 000B, 010B, 000B],            $
  736.         [000B, 000B, 000B, 004B, 000B],            $
  737.         [000B, 000B, 000B, 000B, 000B],            $
  738.         [000B, 000B, 000B, 000B, 000B],            $
  739.         [000B, 000B, 000B, 000B, 000B]            $
  740.         ],                        $
  741.         ;counter clockwise rotation icon
  742.          [                        $
  743.         [000B, 000B, 000B, 000B, 000B],            $
  744.         [000B, 000B, 000B, 000B, 000B],            $
  745.         [000B, 000B, 000B, 000B, 000B],            $
  746.         [000B, 000B, 000B, 000B, 000B],            $
  747.         [000B, 000B, 000B, 000B, 000B],            $
  748.         [000B, 000B, 000B, 000B, 000B],            $
  749.         [000B, 000B, 000B, 254B, 003B],            $
  750.         [000B, 000B, 224B, 001B, 002B],            $
  751.         [000B, 000B, 024B, 000B, 002B],            $
  752.         [000B, 000B, 006B, 000B, 002B],            $
  753.         [000B, 128B, 001B, 000B, 002B],            $
  754.         [000B, 064B, 000B, 000B, 002B],            $
  755.         [000B, 032B, 000B, 000B, 002B],            $
  756.         [000B, 016B, 000B, 000B, 002B],            $
  757.         [000B, 008B, 000B, 000B, 002B],            $
  758.         [000B, 008B, 000B, 252B, 003B],            $
  759.         [000B, 004B, 128B, 003B, 000B],            $
  760.         [000B, 004B, 064B, 000B, 000B],            $
  761.         [000B, 002B, 032B, 000B, 000B],            $
  762.         [000B, 002B, 016B, 000B, 000B],            $
  763.         [000B, 002B, 008B, 000B, 000B],            $
  764.         [000B, 002B, 008B, 000B, 000B],            $
  765.         [000B, 001B, 008B, 000B, 000B],            $
  766.         [000B, 001B, 004B, 000B, 000B],            $
  767.         [000B, 001B, 004B, 000B, 000B],            $
  768.         [000B, 001B, 004B, 000B, 000B],            $
  769.         [248B, 001B, 252B, 000B, 000B],            $
  770.         [016B, 000B, 064B, 000B, 000B],            $
  771.         [032B, 000B, 032B, 000B, 000B],            $
  772.         [064B, 000B, 016B, 000B, 000B],            $
  773.         [128B, 000B, 008B, 000B, 000B],            $
  774.         [000B, 001B, 004B, 000B, 000B],            $
  775.         [000B, 002B, 002B, 000B, 000B],            $
  776.         [000B, 004B, 001B, 000B, 000B],            $
  777.         [000B, 136B, 000B, 000B, 000B],            $
  778.         [000B, 080B, 000B, 000B, 000B],            $
  779.         [000B, 032B, 000B, 000B, 000B],            $
  780.         [000B, 000B, 000B, 000B, 000B],            $
  781.         [000B, 000B, 000B, 000B, 000B],            $
  782.         [000B, 000B, 000B, 000B, 000B]            $
  783.         ],                        $
  784.         ;flip icon
  785.          [                        $
  786.         [000B, 000B, 000B, 000B, 000B],            $
  787.         [000B, 000B, 128B, 000B, 000B],            $
  788.         [000B, 000B, 192B, 000B, 000B],            $
  789.         [000B, 000B, 160B, 000B, 000B],            $
  790.         [000B, 000B, 144B, 000B, 000B],            $
  791.         [000B, 000B, 136B, 000B, 000B],            $
  792.         [000B, 000B, 132B, 000B, 000B],            $
  793.         [000B, 000B, 130B, 000B, 000B],            $
  794.         [000B, 000B, 129B, 000B, 000B],            $
  795.         [000B, 128B, 128B, 000B, 000B],            $
  796.         [000B, 064B, 128B, 000B, 000B],            $
  797.         [000B, 032B, 128B, 000B, 000B],            $
  798.         [000B, 032B, 128B, 000B, 000B],            $
  799.         [000B, 063B, 128B, 255B, 000B],            $
  800.         [224B, 032B, 128B, 000B, 007B],            $
  801.         [024B, 032B, 128B, 000B, 024B],            $
  802.         [004B, 032B, 128B, 002B, 032B],            $
  803.         [028B, 032B, 128B, 006B, 032B],            $
  804.         [228B, 032B, 128B, 010B, 032B],            $
  805.         [004B, 255B, 255B, 019B, 032B],            $
  806.         [004B, 000B, 000B, 032B, 032B],            $
  807.         [004B, 000B, 000B, 192B, 032B],            $
  808.         [004B, 000B, 000B, 128B, 039B],            $
  809.         [004B, 000B, 000B, 000B, 057B],            $
  810.         [004B, 000B, 000B, 000B, 033B],            $
  811.         [008B, 000B, 000B, 128B, 000B],            $
  812.         [048B, 000B, 000B, 064B, 000B],            $
  813.         [192B, 001B, 000B, 032B, 000B],            $
  814.         [000B, 254B, 255B, 019B, 000B],            $
  815.         [000B, 192B, 128B, 010B, 000B],            $
  816.         [000B, 128B, 128B, 006B, 000B],            $
  817.         [000B, 000B, 129B, 002B, 000B],            $
  818.         [000B, 000B, 130B, 000B, 000B],            $
  819.         [000B, 000B, 132B, 000B, 000B],            $
  820.         [000B, 000B, 136B, 000B, 000B],            $
  821.         [000B, 000B, 144B, 000B, 000B],            $
  822.         [000B, 000B, 160B, 000B, 000B],            $
  823.         [000B, 000B, 192B, 000B, 000B],            $
  824.         [000B, 000B, 128B, 000B, 000B],            $
  825.         [000B, 000B, 000B, 000B, 000B]            $
  826.         ],                        $
  827.         ;invert icon
  828.          [                        $
  829.         [000B, 000B, 000B, 000B, 128B],            $
  830.         [224B, 127B, 000B, 000B, 192B],            $
  831.         [024B, 128B, 001B, 000B, 224B],            $
  832.         [004B, 000B, 002B, 000B, 240B],            $
  833.         [004B, 000B, 002B, 000B, 248B],            $
  834.         [098B, 096B, 004B, 000B, 252B],            $
  835.         [098B, 096B, 004B, 000B, 254B],            $
  836.         [002B, 000B, 004B, 000B, 255B],            $
  837.         [002B, 000B, 004B, 128B, 255B],            $
  838.         [002B, 006B, 004B, 192B, 255B],            $
  839.         [002B, 006B, 004B, 224B, 255B],            $
  840.         [002B, 000B, 004B, 240B, 255B],            $
  841.         [002B, 000B, 004B, 248B, 255B],            $
  842.         [034B, 064B, 004B, 252B, 255B],            $
  843.         [098B, 096B, 004B, 254B, 255B],            $
  844.         [196B, 057B, 002B, 255B, 255B],            $
  845.         [004B, 015B, 130B, 255B, 255B],            $
  846.         [024B, 128B, 193B, 255B, 255B],            $
  847.         [224B, 127B, 224B, 255B, 255B],            $
  848.         [000B, 000B, 240B, 255B, 255B],            $
  849.         [000B, 000B, 248B, 000B, 248B],            $
  850.         [000B, 000B, 060B, 255B, 231B],            $
  851.         [000B, 000B, 222B, 255B, 223B],            $
  852.         [000B, 000B, 223B, 255B, 223B],            $
  853.         [000B, 128B, 239B, 252B, 185B],            $
  854.         [000B, 192B, 239B, 252B, 185B],            $
  855.         [000B, 224B, 239B, 255B, 191B],            $
  856.         [000B, 240B, 239B, 255B, 191B],            $
  857.         [000B, 248B, 239B, 255B, 191B],            $
  858.         [000B, 252B, 239B, 159B, 191B],            $
  859.         [000B, 254B, 239B, 159B, 191B],            $
  860.         [000B, 255B, 239B, 255B, 191B],            $
  861.         [128B, 255B, 239B, 255B, 191B],            $
  862.         [192B, 255B, 239B, 253B, 187B],            $
  863.         [224B, 255B, 239B, 249B, 185B],            $
  864.         [240B, 255B, 223B, 099B, 220B],            $
  865.         [248B, 255B, 223B, 015B, 223B],            $
  866.         [252B, 255B, 063B, 255B, 231B],            $
  867.         [254B, 255B, 255B, 000B, 248B],            $
  868.         [255B, 255B, 255B, 255B, 255B]            $
  869.         ]                        $
  870.         ]
  871.  
  872. FOR i = 0,N_ELEMENTS(controls)-1 DO BEGIN
  873.   toss = WIDGET_BUTTON(xbm_palette, $
  874.         VALUE = controlicons[*,*,i], $
  875.         UVALUE = controls[i])
  876. ENDFOR
  877.  
  878. xsize_draw = thexsize * multiplier
  879. ysize_draw = theysize * multiplier
  880. xbm_draw = WIDGET_DRAW(xbm_topbase, $
  881.         XSIZE = xsize_draw, $
  882.         YSIZE = ysize_draw, $
  883.         /BUTTON_EVENTS, $
  884.         /MOTION_EVENTS, $
  885.         RETAIN = 2, $
  886.         UVALUE = "DRAW", $
  887.         /FRAME)
  888.  
  889. showbase = WIDGET_BASE(xbm_editbase, $
  890.         /ROW)
  891.  
  892. xbm_show = WIDGET_DRAW(showbase, $
  893.         XSIZE = thexsize * 2 + 18, $
  894.         YSIZE = theysize + 12, $
  895.         RETAIN = 2, $
  896.         /FRAME)
  897.  
  898. tempbase = WIDGET_BASE(xbm_editbase, $
  899.         /ROW, $
  900.         /FRAME)
  901. label = WIDGET_LABEL(tempbase, $
  902.         VALUE = "Filename:")
  903. nameid = WIDGET_TEXT(tempbase, $
  904.         VALUE = FILENAME, $
  905.         XSIZE = 40, $
  906.         YSIZE = 1, $
  907.         /EDITABLE, $
  908.         UVALUE = "FILENAME")
  909.  
  910. WIDGET_CONTROL, xbm_editbase, /REALIZE            ;create the widgets
  911.                             ;that is defined
  912.  
  913. WIDGET_CONTROL, xbm_draw, GET_VALUE = test1        ;drawwin
  914. WIDGET_CONTROL, xbm_show, GET_VALUE = test2        ;showwin
  915.  
  916. drawwin = test1
  917. showwin = test2
  918.  
  919. WSET, showwin
  920. ERASE, 149
  921.  
  922. update_display
  923. WSET, swin
  924.  
  925. lastx = 0
  926. lasty = 0
  927.  
  928. XManager, "xbm_edit", xbm_editbase, $            ;register the widgets
  929.         EVENT_HANDLER = "xbm_edit_ev", $    ;with the XManager
  930.         GROUP_LEADER = GROUP, /NO_BLOCK
  931.  
  932. END ;================ end of xbm_edit background task =====================
  933.  
  934.  
  935.  
  936.  
  937.  
  938.